<script setup lang="ts">
// 引入echarts
import { onMounted, ref } from 'vue'
import * as echarts from 'echarts'

const charts = ref()
onMounted(() => {
  // 初始化echarts
  const myCharts = echarts.init(charts.value)
  // 设置配置项
  const option = {
    tooltip: {
      trigger: 'item',
    },
    legend: {
      top: '5%', // 图例组件legend 位置设置
      right: 10, // 图例组件legend 位置设置
      orient: 'vertical', // 图例组件legend 方向设置
      textStyle: {
        color: 'white', // legend 文字颜色设置
        fontSize: '14',
      },
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2,
        },
        label: {
          show: true,
          position: 'inside',
        },
        /*emphasis: {
          label: { // 鼠标悬停时放大
            show: true,
            fontSize: 40,
            fontWeight: 'bold',
          },
        },*/
        labelLine: {
          show: false,
        },
        data: [
          { value: 1048, name: 'Search Engine' },
          { value: 735, name: 'Direct' },
          { value: 580, name: 'Email' },
          { value: 484, name: 'Union Ads' },
          { value: 300, name: 'Video Ads' },
        ],
      },
    ],
    grid: {
      left: 0,
      top: 0,
      right: 0,
      bottom: 0,
    },
  }
  // 使用配置项
  myCharts.setOption(option)
})
</script>

<template>
  <div class="box2">
    <div class="title">
      <p>年龄比例</p>
      <img src="../../images/dataScreen-title.png" />
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<style scoped lang="scss">
.box2 {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-lb.png) no-repeat;
  background-size: 100% 100%;
}

.title {
  margin-left: 20px;

  p {
    color: white;
    font-size: 20px;
  }
}

.charts {
  //width: 100%;
  //height: 100%;
  height: calc(100% - 30px);
}
</style>
